# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=soundtouch
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2
pkgrel=1
pkgdesc="An audio processing library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.surina.net/soundtouch/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('strip' 'staticlibs')
source=(https://gitlab.com/soundtouch/soundtouch/-/archive/${pkgver}/${_realname}-${pkgver}.tar.gz
        0001-no-undefined-on.mingw.patch
        0003-fix-docdir.mingw.patch)
sha256sums=('525478c745a51dadaf7adb8e5386ec1f903d47196fab5947dc37414344684560'
            '68d545eedd45afa26723aa2e3d7a447d179c78566308b29fa9d1c6a71476f50d'
            '2cd136046831f3ad9a2e37c0afe3ecd9f25ce27f5dbf4ee8b23b862a96e76cd5')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  sed -i 's/AM_CONFIG_HEADER/AC_CONFIG_HEADER/' configure.ac
  patch -p1 -i ${srcdir}/0001-no-undefined-on.mingw.patch
  patch -p1 -i ${srcdir}/0003-fix-docdir.mingw.patch

  ./bootstrap
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
